media/gstreamer: Support using GL for video for Windows
authorChun-wei Fan <fanchunwei@src.gnome.org>
Sat, 13 Feb 2021 10:40:56 +0000 (18:40 +0800)
committerChun-wei Fan <fanchunwei@src.gnome.org>
Mon, 24 May 2021 08:36:40 +0000 (16:36 +0800)
commit52d1c0c2719a5a729cf17c90262d6f542eab1d11
tree7ab7d45f975b989e89a06af1171079f78520b364
parent21057fb85750b5375b9acd0ff13965c73f551972
media/gstreamer: Support using GL for video for Windows

Add support to share the WGL context in GDK with the WGL context in GStreamer,
so that we can also use OpenGL in the gstreamer media backend to playback
videos.  For now OpenGL/ES is not supported for this under Windows.

The process of setting this up in Windows is a little bit more involved, as:

*  The OpenGL support in GstGL requires a GL 4.1 Core context, but we may just
   get the GL version from wglCreateContextAttribsARB() that we pass into the
   attributes, which is 3.2 by default.  So, try to ask for a 4.1 Core context
   first if we are asking for anything less.

*  There is only one GstDisplay available for Windows, so we just use
   gst_gl_display_new().

*  We must explicitly tell libepoxy that we are using wglMakeCurrent() outside
   of libepoxy that is being used in GdkGL, otherwise we would end up crashing
   as the GL/WGL function pointers would become invalid.

*  We must also deactivate temporarily the underlying WGL context that was made
   current by gdk_gl_context_make_current() so that when
   gst_gl_display_create_context() calls wglShareLists(), we won't get bitten
   by error 0xaa (resource busy), as some drivers don't handle this well when
   the GL context is current in another thread.

For the last two points we make use of macros defined by the platforms that the
build is done for to help us carry out the necessary tasks as needed.

Thanks to Matthew Waters for the info on integrating GstGL and windowing
toolkits on Windows.
gdk/win32/gdkglcontext-win32.c
modules/media/gtkgstpaintable.c
modules/media/gtkgstsink.c